<?php

namespace app\api\controller;

use think\Db;
use app\common\validate\GoodsValidate;

class Goods extends ApiBase
{
	protected $datas;

	/**
	 * 商品详情
	 * @Author   Yichen
	 * @DateTime 2020-05-02T17:32:38+0800
	 * @return   [type]                   [description]
	 */
	public function goodsDetail()
	{
		$this->datas = $this->params;
		$validata = new GoodsValidate();
		if (!$validata->scene('query')->check($this->datas)) {
			return json(['code' => 0, 'msg' => $validata->getError(), 'data' => []]);
		}
		$gid = $this->datas['gid'];
		$goodsPropertyData = Db::name('t_goods')->alias('g')
			->join('t_goods_property gp', 'g.id=gp.goods_id', 'left')
			->where('g.id', $gid)
			->field('gp.id goodsProId,g.name,g.poster,gp.big_images bigImages,gp.price,gp.stock,gp.specifications_name speName')
			->select();
		if (empty($goodsPropertyData)) {
			return json(['code' => 0, 'msg' => '无效的商品号', 'data' => []]);
		}	
		$poster = $goodsPropertyData[0]['poster'];
		foreach ($goodsPropertyData as $key => $value) {
			unset($goodsPropertyData[$key]['poster']);
		}
		return json([
			'code' => 0, 
			'msg' => '', 
			'data' => [
				'goodsInfo' => $goodsPropertyData,
				'poster' => $poster
			]
		]);
	}


	/**
	 * 相关推荐
	 * @Author   Yichen
	 * @DateTime 2020-05-04T18:03:14+0800
	 * @return   [type]                   [description]
	 */
	protected function _recommend()
	{

	}
}